import {Component, Input, OnInit} from '@angular/core';
import {GlobalService} from '../../../service/GlobalService';
import {Constant} from '../../../util/Constant';
import {ModelRes} from '../../../entity/ModelRes';
import {NzModalRef} from 'ng-zorro-antd';
import {StringUtil} from '../../../util/StringUtil';

@Component({
  selector: 'app-admin-detail',
  templateUrl: './admin-detail.component.html',
  styleUrls: ['./admin-detail.component.css']
})
export class AdminDetailComponent implements OnInit {

  @Input()
  obj;

  isUpdate = false;

  constructor(public app: GlobalService, private modal: NzModalRef) {
    console.log('constructor');

  }

  ngOnInit() {
    console.log('ngOnInit');
    if (StringUtil.isBlank(this.obj)) {
      this.obj = {'name': '', 'phone': '', 'auth': 2};
      this.isUpdate = false;
    } else {
      this.isUpdate = true;
    }

  }


  update() {
    let obj;
    let url;
    if (this.isUpdate) {
      obj = {'adminid': this.obj.adminid, 'name': this.obj.name, 'phone': this.obj.phone, 'auth': this.obj.auth};
      url = Constant.ADMIN_UPDATE;
    } else {
      obj = {'name': this.obj.name, 'phone': this.obj.phone, 'auth': this.obj.auth};
      url = Constant.ADMIN_INSERT;
    }
    this.app.toast('操作成功');
  }

}
